package net;

import static org.jboss.netty.channel.Channels.pipeline;

import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.ChannelPipelineFactory;
import org.jboss.netty.handler.timeout.IdleStateHandler;
import org.jboss.netty.util.HashedWheelTimer;
import org.jboss.netty.util.Timer;

import system.Config;
import system.G;

public class ServerPipelineFactory implements ChannelPipelineFactory {
	private Timer _idelTimer;
	private IdleStateHandler _idelHandler;

	public ServerPipelineFactory() {
		_idelTimer = new HashedWheelTimer();
		_idelHandler = new IdleStateHandler(_idelTimer,
				Config.IDEL_TIME_SECEND, Config.IDEL_TIME_SECEND,
				Config.IDEL_TIME_SECEND);
	}

	public ChannelPipeline getPipeline() throws Exception {
		ChannelPipeline pipeline = pipeline(_idelHandler,
				new IdelEventHandler(),
				new DataExtracter(),
				new ServerSocketHandler((MessageDispatcher) G.get("MD")));
		return pipeline;
	}
}
